package com.thread.sync;

import java.util.concurrent.locks.Lock;

public class PrintRunnableLocker implements Runnable {

	private String context;
	private Lock obj;
	private Lock self;
	
	public PrintRunnableLocker(String context, Lock another, Lock self) {
		this.context = context;
		this.obj = another;
		this.self = self;
	}
	
	@Override
	public void run() {
		this.execute();
	}
	
	private void execute(){
		
		int index = 10;
		
		while (index > 0){
			
			obj.lock();
			
			self.lock();
			
			System.out.println(this.context.toUpperCase()+ index);
			index--;
			
			self.unlock();
			
			obj.unlock();
			
		}
		
	}

}
